﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace factoryMethodPattern
{
    class Program
    {
        static void Main(string[] args)
        {
            // 使用具体工厂A创建具体产品A
            IFactory factoryA = new ConcreteFactoryA();
            IProduct productA = factoryA.CreateProduct();
            productA.Operation();

            // 使用具体工厂B创建具体产品B
            IFactory factoryB = new ConcreteFactoryB();
            IProduct productB = factoryB.CreateProduct();
            productB.Operation();

            Console.ReadLine();
        }
    }

    // 抽象产品
    interface IProduct
    {
        //虚方法
        void Operation();
    }

    // 具体产品A
    class ConcreteProductA : IProduct
    {
        public void Operation()
        {
            Console.WriteLine("具体产品A的操作");
        }
    }

    // 具体产品B
    class ConcreteProductB : IProduct
    {
        public void Operation()
        {
            Console.WriteLine("具体产品B的操作");
        }
    }

    // 具体产品C
    class ConcreteProductC : IProduct
    {
        public void Operation()
        {
            Console.WriteLine("具体产品C的操作");
        }
    }



    // 抽象工厂
    interface IFactory
    {
        IProduct CreateProduct();
    }

    // 具体工厂A
    class ConcreteFactoryA : IFactory
    {
        public IProduct CreateProduct()
        {
            return new ConcreteProductA();
        }
    }

    // 具体工厂B
    class ConcreteFactoryB : IFactory
    {
        public IProduct CreateProduct()
        {
            return new ConcreteProductB();
        }
    }


}

